package com.lsa.cormen.ch15.samples;

public class Parenth {

    /**
     * @param args
     */
    public static void main(String[] args) {
        int n = 4;
        String[][] matrix = new String[n+1][n+1]; // 1..n
        init(matrix);
        int count = 1;
        for (int ll = 1; ll <= n; ll++) {
            System.out.println("l="+ll);
            for (int i = 1; i <= n - ll + 1; i++) {
                int j = i + ll - 1;
                System.out.print(String.format("(%s,%s)", i, j));
                for (int k = i; k <= j - 1; k++) {
                    matrix[i][k] = String.format("%2d->(%2d,%2d) ", count++, i, k);
                    matrix[k+1][j] = String.format("%2d->(%2d,%2d) ", count++, k+1, j);
//                    System.out.print(String.format("{(%s,%s)_(%s,%s)} ", i, k, k+1, j));
                }
            }
            System.out.println();
        }
//        print(matrix);
    }
    
    private static void init(String[][] matrix) {
        for (int i = 1; i <= matrix.length-1; i++) {
            for (int j = 1; j <= matrix[i].length-1; j++) {
                matrix[i][j] = String.format("%2s->(%2s,%2s) ", "*", "*","*");
            }
        }
    }

    private static void print(String[][] matrix) {
        for (int i = 1; i <= matrix.length-1; i++) {
            for (int j = 1; j <= matrix[i].length-1; j++) {
                System.out.print(matrix[i][j]);
            }
            System.out.println();
        }
    }
}
